package com.hwua.tonyshop.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.springframework.web.multipart.MultipartFile;

public class FileUtil {
	public static void uploadFile(byte[] file, String filePath, String fileName) throws Exception { 
        File targetFile = new File(filePath);  
        if(!targetFile.exists()){    
            targetFile.mkdirs();    
        } 
        System.out.println(filePath+fileName);
        FileOutputStream out = new FileOutputStream(filePath+fileName);
        out.write(file);
        out.flush();
        out.close();
    }
	
	public static boolean uploadFile(MultipartFile file,String path){
		File targetFile = new File(path);
		if(!targetFile.exists()){
			targetFile.mkdirs();
		}
		
		//保存
		try {
			file.transferTo(targetFile);
		} catch (IllegalStateException e) {
			return false;
		} catch (IOException e) {
			return false;
		}
		return true;
	}
}
